// store.js

const recentUsingTagManager = {
  limit: 7,
  seq: 0,
  tags: {
    // 'example-id': {
    //     'tagId': 1,
    //     'tagName': '/XX',
    //     'seq': 1,
    // }
  },
  addCount(tagId, tagName) {
    let tag = this.tags[tagId];
    if (!tag) {
      tag = {'tagId': tagId,}
      this.tags[tagId] = tag;
    }
    tag['tagName'] = tagName;
    tag['seq'] = (this.seq += 1);
  },
  getRecentTags() {
    let recentTags = Object.values(this.tags);
    recentTags = recentTags.sort((t1, t2) => t1.seq == t2.seq ? 0 : (t1.seq < t2.seq ? 1 : -1))
    let result = [];
    for (let i = 0; i < recentTags.length && i < this.limit; i++) {
        const tag = recentTags[i];
        result.push({'tagId': tag.tagId, 'tagName': tag.tagName});
    }
    return result;
  }

}

export default {
    recentUsingTagManager
}